package net.atomarrow.pr.service;

import java.util.List;

import net.atomarrow.bean.Pager;
import net.atomarrow.db.parser.Conditions;
import net.atomarrow.pr.domain.TbRole;
import net.atomarrow.pr.form.RoleForm;
import net.atomarrow.sy.base.BaseService;
import net.atomarrow.util.StringUtil;

public class RoleService extends BaseService {
	@Override
	protected String getDomainName() {
		return TbRole.class.getSimpleName();
	}

	public List<TbRole> getAllRole() {
		return getList(new Conditions(TbRole.class));
	}

	public List<TbRole> getList(RoleForm form) {
		Conditions conditions = getConditions();
		if (form != null) {
			if (StringUtil.isNotBlank(form.getKeywords())) {
				conditions.parenthesesStart();
				conditions.putLIKE("name", form.getKeywords());
				conditions.setLink(Conditions.OR);
				conditions.putLIKE("remark", form.getKeywords());
				conditions.parenthesesEnd();
			}
		}
		Pager pager = form.getPager();
		if (pager == null) {
			processOrder(form, conditions);
			return this.getList(conditions);
		}
		pager.setDataTotal(this.getCount(conditions));
		processOrder(form, conditions);
		return this.getListByPage(conditions, pager);
	}


}
